pub fn use_struct(){
    println!("use struct");
    create();
    tuple_struct();
    use_struct_as_oo();
    use_static_function();
}

#[derive(Debug)]
struct Site {
    domain: String, // how to use type &str as field ???  life scope ???
    name: String,
    nation: String,
    found: bool
}

fn create(){
    let baidu = Site {
        domain: String::from("www.baidu.com"),
        name: String::from("BAIDU"),
        nation: String::from("China"),
        found: false
    };
    println!("baidu:{:?}", baidu);

    let domain = String::from("www.baidu.com");
    let name = String::from("BAIDU");
    let new_baidu = Site{
        domain,
        name,
        nation: String::from("USA"),
        found: true
    };
    println!("new baidu:{:?}", new_baidu);

    let copy = Site {
        domain : String::from("copy site"),
        ..baidu // baidu's part value are moved !!!!!Note!!!!!
    };
    println!("copy baidu:{:?} from baidu", copy);
}


fn tuple_struct(){
    struct Color(u8, u8, u8);
    let black = Color(0, 0, 0);
    println!("black = ({}, {}, {})", black.0, black.1, black.2);
    let red = Color(255, 0, 0);
    println!("red = ({}, {}, {})", red.0, red.1, red.2);
}

struct Rectangle {
    width: u32,
    height: u32,
}

impl Rectangle {
    fn area(&self) -> u32{
        self.width * self.height
    }
}
fn use_struct_as_oo(){
    let rect = Rectangle{ width: 30, height: 50 };
    println!("rect 's area is {}", rect.area());
}

impl Rectangle {
    //function belong to class Rectangle
    fn create(width: u32, height : u32) -> Rectangle{
        Rectangle{width, height}
    }
}
fn use_static_function(){
    let rect = Rectangle::create(32, 33);
    println!("rect 's area is {}", rect.area());
}
